package javaBase.nowcoder.HJ27_A_查找兄弟单词;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.util.Arrays.*;
import static java.util.Arrays.sort;

public class Main {
    static TreeSet<String> treeSet = new TreeSet<>(new Comparator<String>() {
        @Override
        public int compare(String s1, String s2) {
            int num = s1.compareTo(s2);       //比较内容为主要条件
            return num == 0 ? 1 : num;        //保留重复
        }
    });

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        br.close();

        List<String> strings = new ArrayList<>();
        List<String> strings1 = asList(s.split(" "));
        for (int i = 1; i <= strings1.size() - 1 - 1 - 1; i++) {
            strings.add(strings1.get(i));
        }
        Integer num = Integer.parseInt(strings1.get(strings1.size() - 1));
        String s1 = strings1.get(strings1.size() - 1 - 1);
        strings.stream().filter(x -> isBrother(x, s1)).forEach(y -> {
            treeSet.add(y);
        });
        System.out.println(treeSet.size());
        if (treeSet.size() > num) {
            System.out.println(treeSet.toArray()[num - 1]);
        }


    }

    public static boolean isBrother(String x, String s1) {
        if (x.equals(s1) || x.length() != s1.length()) return false;
        else {
            char[] xs = x.toCharArray();
            char[] s1s = s1.toCharArray();
            sort(xs);
            sort(s1s);
            for (int i = 0; i < xs.length; i++) {
                if (xs[i] != s1s[i]) {
                    return false;
                }
            }
            return true;
        }
    }
}
